from src.GC import noteAgent_LLM
from src.loader import web_loader_llm
from src.utils import file_operate
from src.app import web

# 生成并保存Markdown笔记
def generate_markdown(url):
    # 加载网页内容
    web_content = web_loader_llm.load_web_content(url)
    # 初始化LLM Chain
    llm_chain = noteAgent_LLM.init_llm_chain()
    # 调用LLM生成Markdown
    result = llm_chain.run({"web_content": web_content, "url": url})
    # 保存到本地文件
    filename = file_operate.save_markdown(result)
    # with open(save_path, "w", encoding="utf-8") as f:
    #     f.write(result)
    # print(f"Markdown笔记已保存至：{save_path}")
    return filename


# 5. 执行入口（替换为你要爬取的公开网址）
if __name__ == "__main__":
    # target_url = "https://www.runoob.com/python3/python3-with-keyword.html"
    # generate_markdown(target_url)

    app = web.create_app()
    app.run(host='localhost', port=8080, use_reloader=False)